#!/bin/sh

set -e

# change the next variable to your server ut System folder:
export UT_DATA_PATH="/home/utserver/ut-server/System"
# this should be correct, but change it if not:
UT_PREFS="$HOME/.loki/ut/System"
# where you want the files to ultimately be moved to:
TARGET_DIR="/var/www/uz"
# list of directories to compress:
DIRS="Maps Sounds Music Textures System"
# end of customisations

export LD_LIBRARY_PATH=.:${UT_DATA_PATH}:${LD_LIBRARY_PATH}

if [ ! -r "$UT_DATA_PATH" ]; then
    echo "UT_DATA_PATH not found"
    exit 1
fi


cd $UT_DATA_PATH
mkdir -p "$TARGET_DIR"

for i in $DIRS
do
    for p in ../$i/*
    do
        if [ "$i" != "System" ]; then
            cp -v $p .
        fi
        ./ucc-bin compress `basename $p`
        mv -v $UT_PREFS/`basename $p`.uz "$TARGET_DIR/."
        if [ "$i" != "System" ]; then
            rm `basename $p`
        fi
    done
done